package demo6;

/**
 * 回文子串
 */
public class test1 {
    public int countSubstrings(String s) {
        // 创建dp表
        int n = s.length();
        boolean[][] dp = new boolean[n][n];
        // 初始化

        int count = 0;
        for(int i = n-1; i >= 0; i--){
            for(int j = i; j < n; j++){
                if(s.charAt(i) == s.charAt(j)){
                    dp[i][j] = i+1<j ? dp[i+1][j-1] : true;
                }
                if(dp[i][j]){
                    count++;
                }
            }
        }
        return count;
    }
}
